#coding=utf-8
'''
Created on 2010-12-21

@author: fengbingjian
'''
import time
class cache:
    '''
    classdocs
    '''

    data={}
    size = 0
    intval = 1800
    def __init__(self , size):
        if size < 10:
            self.size = 10
        else:
            self.size = size
    def check_cap(self):
        if len(self.data) >= self.size:
            print u"清除cache"
            t = time.time()
            temp = {}
            for url,last_time in self.data.items():
                if t - last_time < self.intval:
                    #print t - last_time
                    #print t - last_time < self.intval
                    temp[url] = t
            self.data = temp
            print u"cache size=" + str(len(self.data))
    def if_exist(self,url):
        self.check_cap()
        if self.data.has_key(url):
            self.data[url] = time.time()
            print url + u",在缓存中"
            return True
        else:
            self.data[url] = time.time()
            return False
        '''
        Constructor
        '''
        